﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace TestImport.Model.DatabaseRepositories
{
    public abstract partial class DatabaseRepository
    {
        /**************/
        /* Bestelling */
        /**************/

        public DataTable Bestelling_GetData()
        {
            return defaultExecuteReaderDataTable(CommandType.Text, "SELECT bestellingID, datumBestelling, isPlato, isRetour, bestellingNaam, opmerkingIntern, opmerkingPlato, status, isAnnulatie FROM Bestelling");
        }

        public DataTable Bestelling_GetMaxBestellingID()
        {
            return defaultExecuteReaderDataTable(CommandType.Text, "SELECT MAX(bestellingID) AS maxBestellingID FROM Bestelling");
        }

        public void Bestelling_InsertBestelling(DateTime datumBestelling, bool isPlato, bool isRetour, bool isAnnulatie, string bestellingNaam, string opmerkingIntern, string opmerkingPlato, int status)
        {
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(8);
                dbManager.AddParameters(0, "@datumBestelling", datumBestelling);
                dbManager.AddParameters(1, "@isPlato", isPlato);
                dbManager.AddParameters(2, "@isRetour", isRetour);
                dbManager.AddParameters(3, "@isAnnulatie", isAnnulatie);
                dbManager.AddParameters(4, "@bestellingNaam", bestellingNaam);
                dbManager.AddParameters(5, "@opmerkingIntern", opmerkingIntern);
                dbManager.AddParameters(6, "@opmerkingPlato", opmerkingPlato);
                dbManager.AddParameters(7, "@status", status);
                dbManager.ExecuteNonQuery(CommandType.Text, "INSERT INTO Bestelling (datumBestelling, isPlato, isRetour, isAnnulatie, bestellingNaam, opmerkingIntern, opmerkingPlato, status) VALUES (@datumBestelling, @isPlato, @isRetour, @isAnnulatie, @bestellingNaam, @opmerkingIntern, @opmerkingPlato, @status)");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public bool Bestelling_Truncate()
        {
            bool succeed = false;
            try
            {
                dbManager.Open();
                dbManager.ExecuteNonQuery(CommandType.Text, "TRUNCATE TABLE Bestelling");
                succeed = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                dbManager.Dispose();
            }
            return succeed;
        }

    }
}
